Completed
Push — master ( dc838b...dfb2bc )
by Askupa
01:34
created

Amarkal.settings.search.find   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
nc 2
nop 0
dl 0
loc 11
rs 9.2
c 0
b 0
f 0
1
/**
2
 * The search class is used internally to search through the fields and find those
3
 * that match the user's query.
4
 */
5
Amarkal.settings.search = {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
6
    $input: null,
7
    init: function() {
8
        this.$input = $('#settings-search');
9
        this.$input.on('keyup',this.onKeyup.bind(this));
10
    },
11
    onKeyup: function(e) {
0 ignored issues
show
Unused Code introduced by
The parameter e is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
12
        var query = this.$input.val().toLowerCase().replace(/[^\w\d\s]/g,'');
13
            
14
        // The user's search query is longer than 1 character
15
        if(query.length > 0) {
16
            
17
            var $matches = Amarkal.settings.fields.search(query);
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
18
            
19
            Amarkal.settings.sections.deactivate();
20
            Amarkal.settings.header.setSectionTitle('Field Search Results');
21
            Amarkal.settings.header.setSectionSubtitle('');
22
            Amarkal.settings.fields.hideAll();
23
            Amarkal.settings.fields.show($matches);
24
25
            // Textual user feedback
26
            $('#settings-search-results').addClass('visible').text($matches.length ? $matches.length+' settings found' : 'Nothing found');
27
        }
28
29
        // The user's search query is not longer than 1 character
30
        else {
31
            $('#settings-search-results').removeClass('visible').text('');
32
            Amarkal.settings.sections.activate(Amarkal.settings.sections.prevSection);
33
        }
34
    }
35
};